package com.yequan.thread.aqs;

/**
 * @author yq
 * @date 2020/09/15
 */
public class MutexTest {

    private static Mutex lock = new Mutex();
    private static int num = 0;

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            new Thread(() -> add()).start();
        }
        Thread.sleep(3000);
        System.out.println(num);
    }

    public static void add() {
        lock.lock();
        try {
            num++;
            System.out.println(Thread.currentThread().getName());
        } finally {
            lock.unlock();
        }
    }

}
